/* eslint-disable no-use-before-define */
import React from 'react'

// 接收一个组件
// 返回一个新组件
export default function useMouse (Base) {
  class Mouse extends React.Component {
    state = {
      x: 0, y: 0
    }

    move = (e) => {
      console.log('move')
      this.setState({
        x: e.pageX,
        y: e.pageY
      })
    }

    componentDidMount () {
      document.addEventListener('mousemove', this.move)
    }

    componentWillUnmount () {
      document.removeEventListener('mousemove', this.move)
    }

    render () {
      console.log(this.props)
      // return this.props.render(this.state)
      return <Base {...this.state} {...this.props} />
    }
  }

  return Mouse
}
